rm(list = ls())
require(foreign)
require(stats4)
require(mfx)
require(stargazer)

#import data
symmetrydata=read.dta("C:/Users/naten/OneDrive - University of Tennessee/Dean Stuff/data/Expt1.dta")
symmetryframe=data.frame(id=symmetrydata$var1,user_id=symmetrydata$var2,qn=symmetrydata$var3,qid=symmetrydata$var4,order=symmetrydata$var5,bid=symmetrydata$var6,chosen_act=symmetrydata$var9, true_state=symmetrydata$var10)

#reward value
r=10 

#data frame for balls
symframeballs=subset(symmetryframe,user_id>1700)
symframeballs$true_state=symframeballs$true_state+6*(symframeballs$qid==3)+4*(symframeballs$qid==4)+2*(symframeballs$qid==5)
symframeballs$correct=(symframeballs$true_state<=10 & symframeballs$chosen_act==1)+(symframeballs$true_state>10 & symframeballs$chosen_act==2)
ballsqid=unique(symframeballs$qid)

#Variables to be stored
acculin=matrix(rep(0,80),nrow=4,ncol=20)
accupow=matrix(rep(0,80),nrow=4,ncol=20)
accugen=matrix(rep(0,80),nrow=4,ncol=20)
accuexp=matrix(rep(0,80),nrow=4,ncol=20)
accunoneigh=matrix(rep(0,80),nrow=4,ncol=20)
dataaccu=matrix(rep(0,80),nrow=4,ncol=20)

#number of states used by different treatments
Nvec=c(8,12,16,20)

#States for different treatments
states=list()
states[[1]]=c(7:14)
states[[2]]=c(5:16)
states[[3]]=c(3:18)
states[[4]]=c(1:20)

correct=list()
incorrect=list()

symframeballs$distance=abs(symframeballs$true_state-10.5)


#Section 4.5 Regressions************************
symframeballs8=subset(symframeballs,qid==ballsqid[1])
model8state=logitmfx(correct~distance,data=symframeballs8, robust=TRUE, clustervar1 = "user_id") 
stargazer(model8state$mfxest)

symframeballs12=subset(symframeballs,qid==ballsqid[2])
model12state=logitmfx(correct~distance,data=symframeballs12, robust=TRUE, clustervar1 = "user_id") 
stargazer(model12state$mfxest)

symframeballs16=subset(symframeballs,qid==ballsqid[3])
model16state=logitmfx(correct~distance,data=symframeballs16, robust=TRUE, clustervar1 = "user_id") 
stargazer(model16state$mfxest)

symframeballs20=subset(symframeballs,qid==ballsqid[4])
model20state=logitmfx(correct~distance,data=symframeballs20, robust=TRUE, clustervar1 = "user_id") 
stargazer(model20state$mfxest)
#***************************************************
